#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <inttypes.h>

typedef int64_t num_t;
#define num_ph PRId64

num_t longPow(num_t base, int op) {
    num_t res = 1;
    for(int i = 0; i < op; i++) {
        res *= base;
    }
    return res;
}

num_t find_number_upper(num_t min, int scale) {
    num_t result = (min / scale) * scale;
    if (result < min) {
        return result + scale;
    } else {
        return result;
    }
}

num_t find_number_under(num_t max, int scale) {
    num_t result = (max / scale) * scale;
    if (result > max) {
        return result - scale;
    } else {
        return result;
    }
}

int main(void) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int n, m;
        scanf("%d%d", &n, &m);
        num_t range_start = n == 1 ? 0 : longPow(10, n - 1);
        num_t range_stop = longPow(10, n) - 1;
        num_t start_num = find_number_upper(range_start, m);
        num_t stop_num = find_number_under(range_stop, m);
        if (range_stop < m) {
            if (n == 1) {
                printf("1\n");
            } else {
                printf("0\n");
            }
            continue;
        }
        
        num_t result = (stop_num - start_num) / m + 1;
        printf("%" num_ph "\n", result);
    }
    return 0;
}
